<?php
require("../../../libraries/config.php");
require("../../../libraries/dbclass2.php");
require("../../../libraries/function.php");

function truyen_duyet($xcrud)
{
    if ($xcrud->get('primary'))
    {
        $db = Xcrud_db::get_instance();
		$db->query("select duyet from truyen where id=".(int)$xcrud->get('primary'));
		$r1=$db->row();
		if($r1['duyet']==0){
        $query = 'UPDATE truyen SET `duyet` = b\'1\' WHERE id = ' . (int)$xcrud->get('primary');
		}else{
		$query = 'UPDATE truyen SET `duyet` = b\'0\' WHERE id = ' . (int)$xcrud->get('primary');
		}
		$db->query($query);
    }
}

function truyen_pick($xcrud)
{
    if ($xcrud->get('primary'))
    {
        $db = Xcrud_db::get_instance();
		$db->query("select pick from truyen where id=".(int)$xcrud->get('primary'));
		$r1=$db->row();
		if($r1['pick']==0){
        $query = 'UPDATE truyen SET `pick` = b\'1\' WHERE id = ' . (int)$xcrud->get('primary');
		}else{
		$query = 'UPDATE truyen SET `pick` = b\'0\' WHERE id = ' . (int)$xcrud->get('primary');
		}
		$db->query($query);
    }
}
function truyen_delete($xcrud)
{
    if ($xcrud->get('primary'))
    {
        $db = Xcrud_db::get_instance();
		$db->query("select xoa from truyen where id=".(int)$xcrud->get('primary'));
		$r1=$db->row();
		if($r1['xoa']==0){
        $query = 'UPDATE truyen SET `xoa` = b\'1\' WHERE id = ' . (int)$xcrud->get('primary');
		}else{
			  $query = 'UPDATE truyen SET `xoa` = b\'0\' WHERE id = ' . (int)$xcrud->get('primary');
		}
        $db->query($query);
    }
}




function clear_action($xcrud)
{
    if ($xcrud->get('primary'))
    {
    $id=$xcrud->get('primary');
	$db=new Model2;
	$db->connect();
	//$db->nonquery('delete from truyen where id='.$id);
	$db->nonquery('delete from truyen_chuong_link where story_id='.$id);
	$db->nonquery('delete from truyen_chuong where truyen_id='.$id);
	

	$db->nonquery('delete from truyen_chuong_noidung1 where truyen_id='.$id);
	$db->nonquery('delete from truyen_chuong_noidung2 where truyen_id='.$id);
	$db->nonquery('delete from truyen_chuong_noidung3 where truyen_id='.$id);
	$db->nonquery('delete from truyen_chuong_noidung4 where truyen_id='.$id);	
	$db->nonquery('delete from truyen_chuong_noidung5 where truyen_id='.$id);
	$db->nonquery('delete from truyen_chuong_noidung6 where truyen_id='.$id);	
	$db->nonquery('delete from truyen_chuong_noidung7 where truyen_id='.$id);
	$db->nonquery('delete from truyen_chuong_noidung8 where truyen_id='.$id);	
	$db->nonquery('delete from truyen_chuong_noidung9 where truyen_id='.$id);
	$db->nonquery('delete from truyen_chuong_noidung10 where truyen_id='.$id);				
	
	$db->nonquery('delete from truyen_tacgia_fk where truyen_id='.$id);
	$db->nonquery('delete from truyen_theloai_fk where truyen_id='.$id);
	$db->nonquery('delete from truyen_tag_fk where truyen_id='.$id);
	//$db->nonquery('delete from truyensearch where id='.$id);
	$db->close();
    }
}


function chuong_delete($xcrud)
{
    if ($xcrud->get('primary'))
    {
        $db = Xcrud_db::get_instance();
		$db->query("select xoa from truyen_chuong where id=".(int)$xcrud->get('primary'));
		$r1=$db->row();
		if($r1['xoa']==0){
        $query = 'UPDATE truyen_chuong SET `xoa` = b\'1\' WHERE id = ' . (int)$xcrud->get('primary');
		}else{
			  $query = 'UPDATE truyen_chuong SET `xoa` = b\'0\' WHERE id = ' . (int)$xcrud->get('primary');
		}
        $db->query($query);
    }
}

function chuong_trangthai($xcrud)
{
    if ($xcrud->get('primary'))
    {
        $db = Xcrud_db::get_instance();
		$db->query("select trangthai from truyen_chuong where id=".(int)$xcrud->get('primary'));
		$r1=$db->row();
		if($r1['trangthai']==0){
        $query = 'UPDATE truyen_chuong SET `trangthai` = b\'1\' WHERE id = ' . (int)$xcrud->get('primary');
		}else{
			  $query = 'UPDATE truyen_chuong SET `trangthai` = b\'0\' WHERE id = ' . (int)$xcrud->get('primary');
		}
        $db->query($query);
    }
}



function chuong_report($xcrud)
{
    if ($xcrud->get('primary'))
    {
		
		$db = Xcrud_db::get_instance();
		$db->query("select xuly from report_truyen where id=".(int)$xcrud->get('primary'));
		$r1=$db->row();
		if($r1['xuly']==0){
          	 $query = 'update report_truyen set xuly=1,xuly_username="'.$_SESSION['user']['username'].'" WHERE id = ' . (int)$xcrud->get('primary');
       		 $db->query($query);
		}else{
			 $query = 'update report_truyen set xuly=0,xuly_username="'.$_SESSION['user']['username'].'" WHERE id = ' . (int)$xcrud->get('primary');
       		 $db->query($query);
		}

    }
}


function duyetupload($xcrud)
{
    if ($xcrud->get('primary'))
    {
		$db = Xcrud_db::get_instance();
        $query = 'update register_upload set duyet=1 WHERE id = ' . (int)$xcrud->get('primary');
        $db->query($query);
		$query = 'update users set upload=1 WHERE username = "'.$xcrud->get('user').'"';
        $db->query($query);
   
    }
}


?>
